<template>
	<view class="submit">
		<!-- 设备入库 --- 发起提交 -->
		<!-- 资产归属 -->
		<scroll-view scroll-y="true" class="scroll-box">
			<view class="nav">
				<view class="name">资产归属</view>
				<view class="value" @click="getAssetOwnership">
					<view class="text">
						{{ assetOwnership }}
					</view>
					<view class="icon">
						<u-icon name="arrow-right" color="#A7AEBD" size="20"></u-icon>
					</view>
				</view>
			</view>
		
		<!-- 自有资产 -->
		<view class="box" v-if="assetOwnership=== '自有资产' ">
			<u-form :model="form1" :rules="rules1" ref="form1" labelPosition="left" labelWidth="auto" class="form"
			:labelStyle="{fontSize: '32rpx', fontWeight: '600',color: '#445469'}">
				<!-- 设备类型 -->
				<u-form-item label="设备类型" borderBottom labelWidth="200rpx" prop="deviceTypeId" required 
				@click="isShowDeviceType = true">
					<u--input
						v-model="form1.deviceTypeId"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择设备类型"
						border="none">
					</u--input>
					<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				<!-- 设备名称 -->
				<u-form-item label="设备名称" borderBottom labelWidth="200rpx" prop="subDeviceTypeId" required 
				@click="getSubDeviceTypeId">
					<u--input
						v-model="form1.subDeviceTypeId"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择设备类型"
						border="none">
					</u--input>
					<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				<!-- 规格型号 -->
				<u-form-item label="规格型号" borderBottom labelWidth="200rpx"
				@click="getSpecificationModel">
					<u--input
						v-model="form1.specificationModel"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择规格型号"
						border="none">
					</u--input>
					<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				
				<!-- 设备品牌 -->
				<u-form-item label="设备品牌" borderBottom labelWidth="200rpx" prop="brand" required>
					<view class="inputValue">
						<u--input
							v-model="form1.brand"
							placeholder="请输入设备品牌"
							border="none">
						</u--input>
					</view>
				</u-form-item>
				
				<!-- 生产日期 -->
				<u-form-item label="生产日期" borderBottom labelWidth="200rpx" prop="productionDate" required
				@click="isShowProductionDate=true">
					<u--input
						v-model="form1.productionDate"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择生产日期"
						border="none">
					</u--input>
					<u-icon slot="right"  name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				
				<!-- 设备原值 -->
				<!-- <u-form-item label="设备原值" borderBottom labelWidth="200rpx" prop="price" required>
					<view class="inputValue">
						<u--input
							type="number"
							v-model="form1.price"
							placeholder="请输入设备原值"
							border="none">
						</u--input>
						<text>元</text>
					</view>
				</u-form-item> -->
				
				<!-- 设备编号 -->
				<u-form-item label="设备编号" borderBottom labelWidth="200rpx" prop="deviceCode" required>
					<view class="inputValue">
						<u--input
							v-model="form1.deviceCode"
							placeholder="请输入设备编号"
							border="none">
						</u--input>
					</view>
				</u-form-item>
				
				<!-- 存放基地 -->
				<u-form-item label="存放基地" borderBottom labelWidth="200rpx" prop="stationId" required
					@click="isShowStationId=true">
					<u--input
						v-model="form1.stationId"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择存放基地"
						border="none">
					</u--input>
					<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				
				<!-- 存储区域 -->
				<!-- <u-form-item label="存储区域" borderBottom labelWidth="200rpx" prop="storageAreaId" required
					@click="getStorageArea">
					<u--input
						v-model="form1.storageAreaId"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择存储区域"
						border="none">
					</u--input>
					<u-icon  name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item> -->
				
				
				<!-- 设备维养 -->
				<!-- 维养项目 -->
				<view v-for="(item, index) in maintainProject" :key="index" style="margin-top: 30rpx;">
					<u-form-item label="维养项目" borderBottom labelWidth="200rpx"
					@click="getMaintenanceItem(item,index)">
						<u--input
							v-model="item.maintenanceItem"
							disabled
							disabledColor="#ffffff"
							placeholder="请选择维养项目"
							border="none">
						</u--input>
						<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
					</u-form-item>
					
					<!-- 启动日期 -->
					<u-form-item label="启动日期" borderBottom labelWidth="200rpx"
					@click="getStartTime(item,index)">
						<u--input
							v-model="item.startTime"
							disabled
							disabledColor="#ffffff"
							placeholder="请选择启动日期"
							border="none">
						</u--input>
						<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
					</u-form-item>
					
					<!-- 提醒周期 -->
					<u-form-item label="提醒周期" borderBottom labelWidth="200rpx">
						<view class="value2 value-nav mr">
							<view class="none"></view>
							<u-number-box v-model="item.period" :min="0" @change="periodChange(item.period,index)" color="#323233"></u-number-box>
							<view class="day">天</view>
						</view>
					</u-form-item>
					<!-- 添加维养项目 -->
					<view class="addArea"  v-if="maintainProject.length -1  ==  index">
						<!-- <image class="image" src="/static/image/universal/add.png" mode=""></image> -->
						<text class="text color1" @click="getAddmaintaining">添加维养项目</text>
						<text class="text color2" @click="getDelmaintaining(item,index)">删除维养项目</text>
					</view>
				</view>
				
			</u-form>
			
			
		</view>
		
		<!-- 租赁资产 -->
		<view class="box2" v-else>
			<u-form :model="form2" ref="form2" :rules="rules2" labelPosition="left" labelWidth="auto" class="form"
			:labelStyle="{fontSize: '32rpx', fontWeight: '600',color: '#445469'}">
				<!-- 设备类型 -->
				<u-form-item label="设备类型" borderBottom labelWidth="200rpx" prop="deviceTypeId" required 
				@click="isShowDeviceType2 = true">
					<u--input
						v-model="form2.deviceTypeId"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择设备类型"
						border="none">
					</u--input>
					<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				<!-- 设备名称 -->
				<u-form-item label="设备名称" borderBottom labelWidth="200rpx" prop="subDeviceTypeId" required 
				@click="getSubDeviceTypeId2">
					<u--input
						v-model="form2.subDeviceTypeId"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择设备类型"
						border="none">
					</u--input>
					<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				<!-- 规格型号 -->
				<u-form-item label="规格型号" borderBottom labelWidth="200rpx"
				@click="getSpecificationModel2">
					<u--input
						v-model="form2.specificationModel"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择规格型号"
						border="none">
					</u--input>
					<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				
				<!-- 设备编号 -->
				<u-form-item label="设备编号" borderBottom labelWidth="200rpx" prop="deviceCode" required>
					<u--input
						v-model="form2.deviceCode"
						disabledColor="#ffffff"
						placeholder="请输入设备编号"
						border="none">
					</u--input>
					<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				
				<!-- 存放基地 -->
				<u-form-item label="存放基地" borderBottom labelWidth="200rpx" prop="stationId" required
					@click="isShowStationId2=true">
					<u--input
						v-model="form2.stationId"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择存放基地"
						border="none">
					</u--input>
					<u-icon slot="right" name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				
				<!-- 存储区域 -->
				<!-- <u-form-item label="存储区域" borderBottom labelWidth="200rpx" prop="storageAreaId" required
					@click="getStorageArea2">
					<u--input
						v-model="form2.storageAreaId"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择存储区域"
						border="none">
					</u--input>
					<u-icon name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item> -->
				
				<view class="" style="margin-top: 30rpx;"></view>
				
				<!-- 租赁日期 -->
				<u-form-item label="租赁日期" borderBottom labelWidth="200rpx"
					@click="isShowRentDate=true">
					<u--input
						v-model="form2.rentDate"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择租赁日期"
						border="none">
					</u--input>
					<u-icon slot="right"  name="arrow-right" color="#A7AEBD" size="20"></u-icon>
				</u-form-item>
				
				<!-- 租赁时间 -->
				<u-form-item label="租赁时间" borderBottom labelWidth="200rpx">
					<view class="value2 value-nav">
						<text class="none"></text>
						<u-number-box v-model="form2.rentDays" min="0" @change="rentDaysChange" color="#323233"></u-number-box>
						<text class="day">天</text>
					</view>
				</u-form-item>
				
				<!-- 操作人员 -->
				<u-form-item label="操作人员" borderBottom labelWidth="200rpx">
					<view class="inputValue">
						<u--input
							v-model="form2.rentOperator"
							placeholder="请输入操作人员"
							border="none">
						</u--input>
					</view>
				</u-form-item>
				
				<!-- 联系方式 -->
				<u-form-item label="联系方式" borderBottom labelWidth="200rpx">
					<view class="inputValue">
						<u--input
							v-model="form2.phone"
							placeholder="请输入联系方式"
							border="none">
						</u--input>
					</view>
				</u-form-item>
				
				<!-- 设备所属单位 -->
				<u-form-item label="设备所属单位" borderBottom labelWidth="240rpx">
					<view class="inputValue">
						<u--input
							v-model="form2.rentUnit"
							placeholder="请输入设备所属单位"
							border="none">
						</u--input>
					</view>
				</u-form-item>
			</u-form>

		</view>
		
		
			<!-- 自有资产 提交 -->
			<u-button class="confirm" type="primary" :loading="loading" text="提交" v-if="assetOwnership=== '自有资产' " @click="submit1"></u-button>
			
			<!-- 租赁资产 提交 -->
			<u-button class="confirm" type="primary" :loading="loading" text="提交" v-else  @click="submit2"></u-button>
		</scroll-view>
	
		<!-- 资产归属 -->
		<u-action-sheet 
			:actions="assetOwnershipList" 
			:title="'资产归属'" 
			:show="isShowAssetOwnership"
			cancelText="取消"
			@close="isShowAssetOwnership = false"
			@select="AssetOwnershipSelect">
		</u-action-sheet>
		
		<!-- 自有资产 -->
		<!-- 设备类型选择 -->
		<u-picker 
			:show="isShowDeviceType" 
			:columns="deviceTypeList" 
			keyName="name" 
			:closeOnClickOverlay="true"
			@confirm="deviceTypeIdConfirm" 
			@cancel="isShowDeviceType = false"> 
		</u-picker>
		
		<!-- 设备名称选择 -->
		<u-picker
			:show="isShowSubDeviceTypeId" 
			:columns="deviceList" 
			keyName="name" 
			:closeOnClickOverlay="true"
			@confirm="subDeviceTypeConfirm" 
			@cancel="isShowSubDeviceTypeId = false"> 
		</u-picker>
		
		<!-- 规格型号选择 -->
		<u-picker
			:show="isShowSpecificationModel" 
			:columns="specificationModelList" 
			keyName="model" 
			:closeOnClickOverlay="true"
			@confirm="specificationModelConfirm" 
			@cancel="isShowSpecificationModel = false"> 
		</u-picker>
		
		<!-- 生产日期选择  isShowProductionDate-->
		<u-datetime-picker
			:show="isShowProductionDate"
			v-model="defaultDate"
			mode="date"
			@cancel="isShowProductionDate=false"
			@confirm="productionDateConfirm">
		</u-datetime-picker>
		
		<!-- 存放基地 -->
		<u-picker
			:show="isShowStationId" 
			:columns="stationList" 
			keyName="name" 
			:closeOnClickOverlay="true"
			@confirm="stationConfirm" 
			@cancel="isShowStationId = false"> 
		</u-picker>
		
		<!-- 存储区域 -->
		<!-- <u-picker
			:show="isShowStorageAreaId" 
			:columns="storageAreaList" 
			keyName="name" 
			:closeOnClickOverlay="true"
			@confirm="storageAreaConfirm" 
			@cancel="isShowStorageAreaId = false"> 
		</u-picker> -->
		
		<!-- 维养项目 -->
		<u-picker
			:show="isShowMaintenanceItem" 
			:columns="maintenanceItemList" 
			keyName="name" 
			:closeOnClickOverlay="true"
			@confirm="maintenanceItemConfirm" 
			@cancel="isShowMaintenanceItem = false"> 
		</u-picker>
		
		<!-- 启动项目 isShowStartTime-->
		<u-datetime-picker
			:show="isShowStartTime"
			v-model="defaultDate"
			mode="date"
			@cancel="isShowStartTime=false"
			@confirm="startTimeConfirm">
		</u-datetime-picker>
		
		
		<!-- 租赁资产 -->
		<!-- 设备类型 -->
		<u-picker
			:show="isShowDeviceType2" 
			:columns="deviceTypeList" 
			keyName="name" 
			:closeOnClickOverlay="true"
			@confirm="deviceTypeIdConfirm2" 
			@cancel="isShowDeviceType2 = false"> 
		</u-picker>
		
		<!-- 设备名称选择 -->
		<u-picker
			:show="isShowSubDeviceTypeId2" 
			:columns="deviceList" 
			keyName="name" 
			:closeOnClickOverlay="true"
			@confirm="subDeviceTypeConfirm2" 
			@cancel="isShowSubDeviceTypeId2 = false"> 
		</u-picker>
		
		<!-- 规格型号选择 -->
		<u-picker
			:show="isShowSpecificationModel2" 
			:columns="specificationModelList" 
			keyName="model" 
			:closeOnClickOverlay="true"
			@confirm="specificationModelConfirm2" 
			@cancel="isShowSpecificationModel2 = false"> 
		</u-picker>
		
		<!-- 存放基地 -->
		<u-picker
			:show="isShowStationId2" 
			:columns="stationList" 
			keyName="name" 
			:closeOnClickOverlay="true"
			@confirm="stationConfirm2" 
			@cancel="isShowStationId2 = false"> 
		</u-picker>
		
		<!-- 存储区域 -->
		<!-- <u-picker
			:show="isShowStorageAreaId2" 
			:columns="storageAreaList" 
			keyName="name" 
			:closeOnClickOverlay="true"
			@confirm="storageAreaConfirm2" 
			@cancel="isShowStorageAreaId2 = false"> 
		</u-picker> -->
		
		<!-- 租赁日期 isShowRentDate-->
		<u-datetime-picker
			:show="isShowRentDate"
			v-model="defaultDate"
			mode="date"
			@cancel="isShowRentDate=false"
			@confirm="rentDateConfirm">
		</u-datetime-picker>
	</view>
</template>

<script>
	import basePicker from "@/components/basePicker/basePicker.vue"
	import { getDeviceType } from "@/api/emergency/emergencyDispatch.js"
	import { getStationList, getStorageAreaList} from "@/api/baseManage/baseManage.js"
	import { getEqInWarehouseSave, getEqInWarehouseSaveEX } from "@/api/device/deviceEntry.js"
	import { getDeviceTypeAttributeList} from "@/api/materials/materials.js"
	import mixins from "@/utils/mixins.js"
 	import { mapGetters } from "vuex"
	
	export default{
		name: "submit",
		mixins: [mixins],
		components: {
			basePicker
		},
		data() {
			return {
				loading: false,
				form1: {    // 自用资产
					deviceTypeId: "",    	// 设备类型
					subDeviceTypeId: "",        // 设备名称
					specificationModel: "",     // 规格型号
					brand: "",  				// 设备品牌
					productionDate: "",  		// 生产日期
					price: "",                  // 设备原值
					deviceCode: "",             // 设备编号
					stationId: "",              // 存放基地id
					storageAreaId: "", 			// 存放区域id
					// eqInWarehouseItemList:[     // 存放区域列表
					// 	{
					// 		stationId: "",      // 存放基地id
					// 		storageAreaId:"",   // 存放区域id
					// 		num: 1,  			// 入库数量
					// 	}
					// ]
				},
				rules1: {			// 自有资产
					'deviceTypeId': {type: 'string', required: true, message: '请选择设备类型', trigger: ['change','blur'] },
					'subDeviceTypeId': {type: 'string', required: true, message: '请选择设备名称', trigger: ['change','blur']},
					'brand': {type: 'string', required: true, message: '请输入设备品牌', trigger: ['change','blur'] },
					'productionDate': {type: 'string', required: true, message: '请选择生产日期', trigger: ['change','blur'] },
					// 'price': [
					// 	{type: 'string', required: true, message: '请输入设备原值', trigger: ['blur', 'change'] },
					// 	{
					// 		required: true,
					// 		pattern: /^\d+$/,
					// 		message: '请输入设备原值',
					// 		trigger: ['blur']
					// 	},
					// ],
					'deviceCode': {type: 'string', required: true, message: '请输入设备编号', trigger: ['change','blur'] },
					'stationId': {type: 'string', required: true, message: '请选择存放基地', trigger: ['change','blur'] },
					'storageAreaId': {type: 'string', required: true, message: '请选择存储区域', trigger: ['change','blur'] },
				},
				rules2:{
					'deviceTypeId': {type: 'string', required: true, message: '请选择设备类型', trigger: ['change','blur'] },
					'subDeviceTypeId': {type: 'string', required: true, message: '请选择设备名称', trigger: ['change','blur']},
					'deviceCode': {type: 'string', required: true, message: '请输入设备编号', trigger: ['change','blur'] },
					'stationId': {type: 'string', required: true, message: '请选择存放基地', trigger: ['change','blur'] },
					'storageAreaId': {type: 'string', required: true, message: '请选择存储区域', trigger: ['change','blur'] },
				},
				form2: {		// 租赁资产
					deviceTypeId: "",      // 设备名称
					subDeviceTypeId: "",              // 存放基地id
					specificationModel: "",     // 规格型号
					deviceCode: "",             // 设备编号
					storageAreaId: "", 			// 存放区域id
					eqInWarehouseItemList:[     // 存放区域列表
						{
							stationId: "",      // 存放基地id
							storageAreaId:"",   // 存放区域id
							num: "",  			// 入库数量
						}
					],
					rentDate: "",               // 租赁日期
					rentDays: "",               // 租赁天数
					rentOperator: "",           // 操作人员
					phone:"",                   // 联系方式
					rentUnit: "",               // 设备所属单位
				},
				
				maintainProject: [                   // 设备维养
					{
						code: "",
						maintenanceItem: "",         // 维养项目
						period: 0,                   // 提醒周期
						startTime: "",               // 启动日期
					}
				],
				isShowAssetOwnership: false,		 	// 资产归属弹框
				isShowDeviceType: false,        		// 自有资产 设备类型弹框
				isShowSubDeviceTypeId: false,        	// 自有资产 设备名称弹框
				isShowSpecificationModel: false,        // 自有资产 规格型号
				isShowProductionDate: false,            // 自有资产 生产日期弹框
				isShowStationId: false,                 // 自有资产 存放基地弹框
				isShowStorageAreaId: false,             // 自有资产 存储区域弹框
				isShowMaintenanceItem: false,           // 自有资产 维养项目弹框
				isShowStartTime: false,                 // 自有资产 启动日期
				isShowDeviceType2: false,               // 租赁资产 设备类型
				isShowSubDeviceTypeId2: false,          // 租赁资产 设备名称
				isShowSpecificationModel2: false,       // 租赁资产 规格型号
				isShowStationId2: false,                // 租赁资产 存放基地
				isShowStorageAreaId2:false,             // 租赁资产 存储区域
				defaultDate: Number(new Date()),        // 默认时间
				isShowRentDate: false,                           // 租赁资产 租赁日期
				// assetOwnershipList:[],                // 资产归属数据
				assetOwnershipList: [{
						code: "zyzc",
						id: 111,
						name: "自有资产"
					},
					{
						code: "zpzc",
						id: 112,
						name: "租赁资产"
					},
				],
				maintenanceItemList: [],              // 维养项目列表
				assetOwnership: "自有资产",            // 资产归属
				deviceTypeList: [],                   // 设备类型数据
				deviceList: [],                       // 设备数据
				stationList: [],                      // 基地数据
				storageAreaList: [],                  // 存储区域数据
				specificationModelList: [],           // 规格型号数据
				sumList: []
			}
		},
		computed: {
			...mapGetters(['dictMap'])
		},
		mounted(){
			// 资产归属
			if(this.dictMap){
				this.assetOwnershipList = this.dictMap.asset_ownership
				this.maintenanceItemList = [this.dictMap.maintenance_item]
				// this.equipmentModelList = this.dictMap.equipment_model
			}
			this.getDeviceTypeList()
			this.getStationList()
			this.getDeviceTypeAttributeList()
		},
		watch:{
			assetOwnership(newVal,oldVal){
				if(newVal === "自有资产"){
					this.clearForm1()
					this.$nextTick(()=>{
						// this.$refs.form2.setRules(this.rules2)
						this.$refs.form1.clearValidate()
					})
				}
				if(newVal === "租赁资产"){
					this.clearForm2()
					this.$nextTick(()=>{
						this.$refs.form2.clearValidate()
					})
					
				}
			}
		},
		onReady() {
			// 如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则
			this.$refs.form1.setRules(this.rules1)
		},
		methods: {
			// 资产归属选择
			getAssetOwnership(){
				this.isShowAssetOwnership = true
			},
			
			// 资产归属的select事件
			AssetOwnershipSelect(data){
				// console.log(data,'data')
				this.isShowAssetOwnership = false
				this.assetOwnership = data.name
				this.tempAssetOwnershipId = data.id
				if(this.assetOwnership === "租赁资产"){
					this.$nextTick(()=>{
						this.$refs.form2.setRules(this.rules2)
					})
				}else{
					this.$nextTick(()=>{
						this.$refs.form1.setRules(this.rules1)
					})
					
				}
			},
			
			// 获取设备数据
			getDeviceTypeList(){
				let _data ={
					name: "",
					ex1: 'equipment',
				}
				// 设备类型 树结构
				getDeviceType(_data).then(res=>{
					this.deviceTypeList = [res.result.filter(item=> item.treeLevel ==2)]
					this.tempList = res.result
					// console.log(this.deviceTypeList)
				})
			},
			
			// 获取基地数据
			getStationList(){
				getStationList({typeIds: [102,104], name: ""}).then(res=>{
					this.stationList = [res.result]
					// console.log(res.result)
				})
			},
			
			// 获取规格型号数据
			async getDeviceTypeAttributeList(){
				let res = await getDeviceTypeAttributeList({currPage: 1,pageSize: 10000,params:{type:"equipment"}})
				this.sumList = res.result.list || []
			},
			
			
			// 自有资产 添加维养项目
			getAddmaintaining(){
				let obj = {
					code: "",
					maintenanceItem: "",
					period: 0,
					startTime: ""
				}
				this.maintainProject.push(obj)
			},
			
			// 自有资产 删除维养项目
			getDelmaintaining(item,index){
				if(this.maintainProject.length > 1){
					this.maintainProject.splice(index,1)
				}
			},
					
			// 自有资产 提交
			submit1(){
				this.$refs.form1.validate().then(res => {
					this.getSave1()
				}).catch(errors => { })
			},
			
			async getSave1(){
				if(this.loading) return
				this.loading = true
				let form = {
					assetOwnership: this.assetOwnership,
					deviceTypeId: this.tempDeviceTypeId,
					subDeviceTypeId: this.tempSubDeviceTypeId,
					specificationModel: this.form1.specificationModel,
					subDeviceTypeName: this.form1.deviceTypeId,
					brand: this.form1.brand,
					productionDate: this.form1.productionDate,
					// price: this.form1.price,
					price: 0,
					stationId: this.tempStationId,
					eqCode: this.form1.deviceCode,
					eqInWarehouseItemList:[
						{
							stationId: this.tempStationId,
							storageAreaId: this.tempStorageAreaId,
							num: 1
						}
					]
				}
				let res = await getEqInWarehouseSave(form)
				if(res.success){
					let code = res.result.code
					this.maintainProject.forEach(item=>{
						item.code = code
					})
					this.maintainProject.forEach(item=>{
						// 提交维养记录
						getEqInWarehouseSaveEX(item).then(respone=>{
							this.loading = false
						})
					})
					this.clearForm1(true)
					this.$nextTick(()=>{
						this.$refs.form1.clearValidate()
					})
					uni.showToast({
						icon: "none",
						title: "保存成功"
					})
				}
			},
			
			// 租赁资产提交
			submit2(){
				this.$refs.form2.validate().then(res=>{
					// console.log(this.form2)
					this.getSave2()
				})
			},
			
			async getSave2(){
				if(this.loading) return
				this.loading = true
				let form = {
					assetOwnership: this.assetOwnership,
					deviceTypeId: this.tempDeviceTypeId2,
					subDeviceTypeId: this.tempSubDeviceTypeId2,
					subDeviceTypeName: this.form2.deviceTypeId,
					specificationModel: this.form2.specificationModel,
					stationId: this.tempStationId2,
					eqCode: this.form2.deviceCode,
					eqInWarehouseItemList: [
						{
							stationId: this.tempStationId2,
							storageAreaId: this.storageId2,
							num: 1
						}
					],
					rentDate: this.form2.rentDate,
					rentDays: this.form2.rentDays,
					rentOperator: this.form2.rentOperator,
					phone: this.form2.phone,
					rentUnit: this.form2.rentUnit
				}
				let res = await getEqInWarehouseSave(form)
				console.log(form,'form')
				if(res.success){
					this.clearForm2(true)
					this.$nextTick(()=>{
						this.$refs.form2.clearValidate()
					})
					uni.showToast({
						icon: "none",
						title: "保存成功"
					})
				}
				this.loading = false
			},
			
			// 自有资产 设备类型 confirm 事件
			deviceTypeIdConfirm(val){
				this.form1.deviceTypeId = val.value[0].name
				this.tempDeviceTypeId = val.value[0].id
				this.form1.subDeviceTypeId = ""
				this.tempSubDeviceTypeId = ""
				this.form1.specificationModel =""
				this.isShowDeviceType = false
				this.$refs.form1.validateField("deviceTypeId")
			},
			
			// 自有资产 点击设备名称
			getSubDeviceTypeId(){
				if(this.form1.deviceTypeId){
					this.deviceList = [this.tempList.filter(item=>item.parentId === this.tempDeviceTypeId)]
					this.isShowSubDeviceTypeId = true
				}else{
					uni.showToast({
						icon: "none",
						title: "请先选择设备类型"
					})
				}
			},
			
			// 自有资产 设备名称 confirm 事件
			subDeviceTypeConfirm(val){
				this.form1.subDeviceTypeId = val.value[0].name
				this.tempSubDeviceTypeId = val.value[0].id
				this.form1.specificationModel = ""
				this.isShowSubDeviceTypeId = false
				this.$refs.form1.validateField("subDeviceTypeId")
			},
			
			// 自有资产 点击规格型号
			getSpecificationModel(){
				if(this.form1.subDeviceTypeId){
					this.specificationModelList = [this.sumList.filter(item=>this.tempSubDeviceTypeId === item.subDeviceTypeId)]
					this.isShowSpecificationModel = true
				}else{
					uni.showToast({
						icon: "none",
						title: "请先选择设备名称"
					})
				}
			},
			
			// 自有资产 规格型号 confirm 事件
			specificationModelConfirm(val){
				this.form1.specificationModel = val.value[0].model
				this.isShowSpecificationModel = false
			},
			
			// 自有资产 生产日期 confirm
			productionDateConfirm(val){
				let time = this.getDate(val.value)
				this.form1.productionDate = time
				this.isShowProductionDate = false
				this.$refs.form1.validateField("productionDate")
			},
			
			// 自有资产 存放基地 confirm
			async stationConfirm(val){
				this.tempStationId = val.value[0].id
				this.form1.stationId = val.value[0].name
				// this.form1.storageAreaId = ""
				// this.tempStorageAreaId = ""
				this.isShowStationId = false
				this.$refs.form1.validateField("stationId")
				
				
				// 获取默认存储区域
				let _query = {
					currPage: 1,
					pageSize: 10000,
					params: {
						stationId: this.tempStationId
					},
				}
				let res = await getStorageAreaList(_query)
				let obj = res.result.list[0] || {}
				this.form1.storageAreaId = obj.name || null
				this.tempStorageAreaId = obj.id || null
				// console.log(this.form1.storageAreaId, this.tempStorageAreaId, obj )
			},
			
			// 自有资产 点击存储区域
			// async getStorageArea(){
			// 	if(this.form1.stationId){
			// 		if(this.tempStationId){
			// 			let _query = {
			// 				currPage: 1,
			// 				pageSize: 10000,
			// 				params: {
			// 					stationId: this.tempStationId
			// 				},
			// 			}
			// 			let res = await getStorageAreaList(_query)
			// 			this.storageAreaList = [res.result.list]
			// 			console.log(this.storageAreaList,'000000')
			// 			this.isShowStorageAreaId = true
			// 		} 
					
			// 	}else{
			// 		uni.showToast({
			// 			icon: "none",
			// 			title: "请先选择存储基地"
			// 		})
			// 	}
			// },
			
			// // 自有资产 存储基地 confirm
			// storageAreaConfirm(val){
			// 	this.form1.storageAreaId = val.value[0].name
			// 	this.tempStorageAreaId = val.value[0].id
			// 	this.isShowStorageAreaId = false
			// 	this.$refs.form1.validateField("storageAreaId")
			// },
			
			// 自有资产 点击 维养项目
			getMaintenanceItem(item,index){
				this.maintenanceItemIndex = index
				this.isShowMaintenanceItem = true
				console.log(item,index)
			},
			
			// 自有资产 维养项目 confirm 事件
			maintenanceItemConfirm(val){
				this.maintainProject.forEach((item,index)=>{
					if(index === this.maintenanceItemIndex){
						item.maintenanceItem = val.value[0].name
					}
				})
				this.isShowMaintenanceItem = false
			},
			
			// 自有资产 点击 启动周期
			getStartTime(item,index){
				this.defaultDate = Number(new Date())
				this.startTimeIndex = index
				this.isShowStartTime = true
			},
			
			// 自有资产 启动日期 confirm 事件
			startTimeConfirm(val){
				let time = this.getDate(val.value)
				this.maintainProject.forEach((item,index)=>{
					if(index === this.startTimeIndex){
						item.startTime = time
					}
				})
				this.isShowStartTime = false
			},
			
			// 自有资产 提醒周期 change事件
			periodChange(val,currentIndex){
				this.maintainProject.forEach((item,index)=>{
					if(index === currentIndex){
						item.period = val
					}
				})
			},
			
			// 租赁资产 设备类型 confirm
			deviceTypeIdConfirm2(val){
				this.form2.deviceTypeId = val.value[0].name
				this.tempDeviceTypeId2 = val.value[0].id
				this.form2.subDeviceTypeId = ""
				this.tempSubDeviceTypeId2 = ""
				this.form2.specificationModel = ""
				this.isShowDeviceType2 = false
				this.$refs.form2.validateField("deviceTypeId")
			},
			
			// 租赁资产 点击设备名称
			getSubDeviceTypeId2(){
				if(this.form2.deviceTypeId){
					this.deviceList = [this.tempList.filter(item=>item.parentId === this.tempDeviceTypeId2)]
					this.isShowSubDeviceTypeId2 = true
				}else{
					uni.showToast({
						icon: "none",
						title: "请先选择设备类型"
					})
				}
			},
			
			// 租赁资产 设备名称 confirm
			subDeviceTypeConfirm2(val){
				this.form2.subDeviceTypeId = val.value[0].name
				this.tempSubDeviceTypeId2 = val.value[0].id
				this.form2.specificationModel = ""
				this.isShowSubDeviceTypeId2 = false
				this.$refs.form2.validateField("subDeviceTypeId")
			},
			
			// 自有资产 点击规格型号
			getSpecificationModel2(){
				if(this.form2.subDeviceTypeId){
					this.specificationModelList = [this.sumList.filter(item=>this.tempSubDeviceTypeId2 === item.subDeviceTypeId)]
					this.isShowSpecificationModel2 = true
				}else{
					uni.showToast({
						icon: "none",
						title: "请先选择设备名称"
					})
				}
			},
			
			// 自有资产 规格型号 confirm 事件
			specificationModelConfirm2(val){
				this.form2.specificationModel = val.value[0].model
				this.isShowSpecificationModel2 = false
			},
			
			// 租赁资产 存放基地
			async stationConfirm2(val){
				this.tempStationId2 = val.value[0].id
				this.form2.stationId = val.value[0].name
				// this.form2.storageAreaId = ""
				// this.storageId2 = ""
				this.isShowStationId2 = false
				this.$refs.form2.validateField("stationId")
				
				// 获取默认存储区域
				let _query = {
					currPage: 1,
					pageSize: 10000,
					params: {
						stationId: this.tempStationId2
					},
				}
				let res = await getStorageAreaList(_query)
				let obj = res.result.list[0] || {}
				this.form2.storageAreaId = obj.name || null
				this.storageId2 = obj.id || null
			},
			
			// 租赁资产 点击 存储区域
			// async getStorageArea2(item, index){
			// 	if(this.form2.stationId){
			// 		if(this.tempStationId2){
			// 			let _query = {
			// 				currPage: 1,
			// 				pageSize: 10000,
			// 				params: {
			// 					stationId: this.tempStationId2
			// 				},
			// 			}
			// 			let res = await getStorageAreaList(_query)
			// 			this.storageAreaList = [res.result.list]
			// 			this.isShowStorageAreaId2 = true
			// 		} 
					
			// 	}else{
			// 		uni.showToast({
			// 			icon: "none",
			// 			title: "请先选择存储基地"
			// 		})
			// 	}
			// },
			
			// // 租赁资产 存储区域 confirm
			// storageAreaConfirm2(val){
			// 	this.form2.storageAreaId = val.value[0].name
			// 	this.storageId2 = val.value[0].id
			// 	this.isShowStorageAreaId2 = false
			// 	this.$refs.form2.validateField("storageAreaId")
			// },
			
			// 租赁资产 租赁日期
			rentDateConfirm(val){
				let time = this.getDate(val.value)
				this.form2.rentDate = time
				this.isShowRentDate = false
			},
			
			// 租赁时间  change事件
			rentDaysChange(val){
				this.form2.rentDays = val
			},
			
			
			clearForm1(bool){
				if(bool){
					this.assetOwnership = "自有资产"
				}
				this.form1 =  {    // 自有资产
					deviceTypeId: "",    	// 设备类型
					subDeviceTypeId: "",        // 设备名称
					specificationModel: "",     // 规格型号
					brand: "",  				// 设备品牌
					productionDate: "",  		// 生产日期
					price: "",                  // 设备原值
					deviceCode: "",             // 设备编号
					stationId: "",              // 存放基地id
					storageAreaId: "", 			// 存放区域id
					// eqInWarehouseItemList:[     // 存放区域列表
					// 	{
					// 		stationId: "",      // 存放基地id
					// 		storageAreaId:"",   // 存放区域id
					// 		num: 1,  			// 入库数量
					// 	}
					// ]
				}
				this.maintainProject= [                   // 设备维养
					{
						code: "",
						maintenanceItem: "",         // 维养项目
						period: 0,                   // 提醒周期
						startTime: "",               // 启动日期
					}
				]
			},
			
			clearForm2(bool){
				if(bool){
					this.assetOwnership = "租赁资产"
				}
				this.form2 ={		// 租赁资产
					deviceTypeId: "",      // 设备名称
					subDeviceTypeId: "",              // 存放基地id
					specificationModel: "",     // 规格型号
					deviceCode: "",             // 设备编号
					storageAreaId: "", 			// 存放区域id
					eqInWarehouseItemList:[     // 存放区域列表
						{
							stationId: "",      // 存放基地id
							storageAreaId:"",   // 存放区域id
							num: "",  			// 入库数量
						}
					],
					rentDate: "",               // 租赁日期
					rentDays: "",               // 租赁天数
					rentOperator: "",           // 操作人员
					phone:"",                   // 联系方式
					rentUnit: "",               // 设备所属单位
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.submit{
		.scroll-box{
			max-height: calc(100vh - 342rpx);
			padding-top: 10rpx;
		}
		.box{
			padding: 0rpx 30rpx;
		}
		.box2{
			padding: 0rpx 30rpx;
			margin-bottom: 40rpx;
		}
		.nav{
			display: flex;
			align-items: center;
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			border-bottom: 2rpx solid #e8ebf1;
			box-sizing: border-box;
			font-family: PingFang SC-Medium, PingFang SC;
			padding: 0rpx 30rpx;
			.name{
				width: 200rpx;
				font-size: 32rpx;
				font-weight: bold;
				color: #445469;
			}
			.value{
				flex: 1;
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 32rpx;
				font-weight: 500;
				color: #22204E;
			}
		}
		
		.inputValue{
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
		.value2{
			display: flex;
			align-items: center;
			text-align: right;
			.none{
				flex: 1;
			}
			
		}
		.value-nav{
			position: relative;
			.day{
				position: absolute;
				right: -100rpx;
			}
		}
		.value-nav.mr{
			position: relative;
			margin-right: 220rpx;
			.day{
				position: absolute;
				right: -100rpx;
			}
		}
		.addArea{
			width: 100%;
			height: 96rpx;
			line-height: 96rpx;
			background: #F5F7FA;
			font-size: 32rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			margin-top: 40rpx;
			margin-bottom: 40rpx;
			text-align: center;
			display: flex;
			.text{
				flex: 1;
			}
			.color1{
				background-color: #317fed;
				color: #FFFFFF;
			}
			.color2{
				background-color: #fe6a6a;
				color: #FFFFFF;
			}
			.image{
				width: 50rpx;
				height: 50rpx;
				margin-bottom: -13rpx;
			}
		}
		.confirm{
			width: 100%;
			height: 92rpx;
			line-height: 92rpx;
			text-align: center;
			color: #FFFFFF;
			background: #2F80ED;
			margin-top: 88rpx;
			margin-bottom: 72rpx;
		}
	}
	
</style>